package com.gym.openapi.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gym.openapi.common.ResponseResult;
import com.gym.openapi.common.ResultTable;
import com.gym.openapi.dao.ApiSystemparamMapper;
import com.gym.openapi.entity.ApiSystemparam;
import com.gym.openapi.services.SystemParamterServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ming
 * 2021/11/26
 * description:系统参数管理
 */
@Service
public class SystemParamterServicesImpl implements SystemParamterServices {
    @Autowired
    private ApiSystemparamMapper asm;

    @Override
    public ResultTable sysTable(Integer page, Integer limit, String name,Integer state) {
        PageHelper.startPage(page, limit);
        List<ApiSystemparam> as = asm.sysTable(name, state) ;
        PageInfo<ApiSystemparam> pas = new PageInfo(as);
        return new ResultTable(0,"msg", (int) pas.getTotal(),pas.getList());
    }

    @Override
    public ResponseResult del(Integer[] ids) {
        int i = asm.del(ids);
        if (i>0) {
            return ResponseResult.getSuccess("sys删除成功");
        }
        return ResponseResult.getFail("sys删除失败");
    }

    @Override
    public ResponseResult update(ApiSystemparam as1) {
        if (as1!=null) {
            int i = asm.updateByPrimaryKeySelective(as1);
            if (i>0) {
                return ResponseResult.getSuccess("好了");
            }
        }
        return ResponseResult.getFail("不行啊");
    }

    @Override
    public ResponseResult add(ApiSystemparam as2) {
        if (as2!=null) {
            int i = asm.insertSelective(as2);
            if (i>0) {
                return ResponseResult.getSuccess();
            }
        }
        return ResponseResult.getFail("添加失败失败asm");
    }


}
